package frame.tool.mapper;

import frame.tool.to.Story;
import frame.tool.qo.StoryQo;

import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

 /**
 * 对应表：tool_story 对应实体类：Story
 * <br>
 * @author PeiWentao
 * @since 2020-06-30 11:30
 */
public interface StoryMapper extends Mapper<Story> {

	// 字段
    String FIELDS = "t.title,t.author,t.content,t.description,t.valid,t.create_time,t.update_time,t.id";
    // 表名 as 别名
    String TABLE = "tool_story t";
    // mapper包名
    String PACKAGE = "frame.tool.mapper";

    @Results({
        @Result(column = "id", property = "id",id = true),
    })
    @Select("<script>SELECT " + FIELDS + " FROM " + TABLE
            + " WHERE t.valid=#{valid}"
            + "<when test='title!=null'> AND t.title LIKE CONCAT('%',#{title},'%')</when>"
            + "</script>")
	List<Story> pageList(StoryQo qo);

    @Select("SELECT " + FIELDS + " FROM " + TABLE + " WHERE t.title=#{0}")
    Story getByTitle(String title);
}
